// 永恒小姐姐
import plugin from '../../../lib/plugins/plugin.js';
import fetch from 'node-fetch';
import fs from 'node:fs';

// Set up path for saving video file
const _path = process.cwd();
if (!fs.existsSync(`./resources/video/`)) {
  fs.mkdirSync(`./resources/video/`);
}

// Define sjxjj class
export class sjxjj extends plugin {
  constructor() {
    super({
      // Set name, description, event type, priority level, and message rules
      name: '来点小姐姐',
      dsc: '发送小姐姐视频',
      event: 'message',
      priority: 5500,
      rule: [
        {
          reg: '^来点好看的$',
          fnc: 'sjxjj'
        }
      ]
    })
  }

  // Define sjxjj method to send a random girl video
  async sjxjj(e) {
    // Choose API endpoint for getting video data
    let api = `https://api.caonm.net/api/mn/index.php`;

    // Fetch video data from API
    let response = await fetch(api);
    let buff = await response.arrayBuffer();

    // Save video to file system and send video segment as reply
    fs.writeFile("./resources/video/sjxjj.mp4", Buffer.from(buff), "binary", function (err) {
      console.log(err || "下载视频成功");
      if (!err) {
        e.reply(segment.video(`file:///${_path}/resources/video/sjxjj.mp4`));
      }
    });
  }
}
